package sk.klimo.prototyp.server;

import java.util.List;

import javax.servlet.ServletContext;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import sk.klimo.prototyp.client.InvoiceService;
import sk.klimo.prototyp.client.model.Invoice;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class InvoiceServiceImpl extends RemoteServiceServlet implements
		InvoiceService {

	private InvoiceDAO invoiceDAO;

	private ApplicationContext getAppContext() {
		ServletContext servletContext = this.getServletContext();

		WebApplicationContext wac = WebApplicationContextUtils
				.getRequiredWebApplicationContext(servletContext);

		return wac;
	}

	public Invoice getInvoice(String cislo) {
		return ((InvoiceDAO) getAppContext().getBean("invoiceDAO"))
				.getInvoice(cislo);
	}

	public List<Invoice> getInvoices() {
		return ((InvoiceDAO) getAppContext().getBean("invoiceDAO"))
				.getInvoices();
	}
}
